package com.example.demo.controller;

import com.example.demo.pojo.Page;
import com.example.demo.service.StatsService;
import com.example.demo.service.TransactionService;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/home")
@Controller
public class HomeController {

    @Autowired
    private UserService userService;

    @Autowired
    private TransactionService transactionService;

    @Autowired
    private StatsService statsService;

    @RequestMapping("/main")
    public String mainPage(Model model, HttpServletRequest request) {

        Page page = userService.searchUsers(1, "");
        Page page1 = transactionService.transAllList(1);

        String username1 = (String) request.getSession().getAttribute("username_login");
        Integer count = statsService.countLogin();
        model.addAttribute("count", count);
        model.addAttribute("username_admin", username1);
        model.addAttribute("page", page);
        model.addAttribute("page1", page1);
        return "/index";
    }
}
